package com.fumihiko.modules.jxxm.service.impl;

import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.fumihiko.common.utils.PageUtils;
import com.fumihiko.common.utils.Query;

import com.fumihiko.modules.jxxm.dao.AllDao;
import com.fumihiko.modules.jxxm.entity.AllEntity;
import com.fumihiko.modules.jxxm.service.AllService;


@Service("allService")
public class AllServiceImpl extends ServiceImpl<AllDao, AllEntity> implements AllService {

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        String myStatus = (String)params.get("myStatus");
        String name = (String)params.get("name");
        String idNo = (String)params.get("idNo");
        String personType = (String)params.get("personType");
        String originalTroops = (String)params.get("originalTroops");
        String retirementStatus = (String)params.get("retirementStatus");
        String duties = (String)params.get("duties");
        String county = (String)params.get("county");
        String street = (String)params.get("street");
        String birthDate1 = (String)params.get("birthDate1");
        String birthDate2 = (String)params.get("birthDate2");
        String retirementTime1 = (String)params.get("retirementTime1");
        String retirementTime2 = (String)params.get("retirementTime2");
        String workTime1 = (String)params.get("workTime1");
        String workTime2 = (String)params.get("workTime2");

        IPage<AllEntity> page = this.page(
                new Query<AllEntity>().getPage(params),
                new QueryWrapper<AllEntity>().
                        like(StringUtils.isNotBlank(myStatus),"my_status", myStatus).
                        like(StringUtils.isNotBlank(name),"name", name).
                        eq(StringUtils.isNotBlank(idNo),"id_no",idNo).
                        eq(StringUtils.isNotBlank(personType),"person_type",personType).
                        like(StringUtils.isNotBlank(originalTroops),"original_troops", originalTroops).
                        like(StringUtils.isNotBlank(retirementStatus),"retirement_status", retirementStatus).
                        like(StringUtils.isNotBlank(duties),"duties",duties).
                        like(StringUtils.isNotBlank(county),"county", county).
                        like(StringUtils.isNotBlank(street),"street", street).
                        ge(StringUtils.isNotBlank(birthDate1),"birth_date", birthDate1).
                        le(StringUtils.isNotBlank(birthDate2),"birth_date", birthDate2).
                        ge(StringUtils.isNotBlank(retirementTime1),"retirement_time", retirementTime1).
                        le(StringUtils.isNotBlank(retirementTime2),"retirement_time", retirementTime2).
                        ge(StringUtils.isNotBlank(workTime1),"work_time", workTime1).
                        le(StringUtils.isNotBlank(workTime2),"work_time", workTime2).
                        orderByDesc("person_type")
        );

        return new PageUtils(page);
    }

    @Override
    public PageUtils searchPage(Map<String, Object> params) {
        String myStatus = (String)params.get("myStatus");
        String name = (String)params.get("name");
        String idNo = (String)params.get("idNo");
        String personType = (String)params.get("personType");
        String originalTroops = (String)params.get("originalTroops");
        String retirementStatus = (String)params.get("retirementStatus");
        String duties = (String)params.get("duties");
        String county = (String)params.get("county");
        String street = (String)params.get("street");
        String birthDate1 = (String)params.get("birthDate1");
        String birthDate2 = (String)params.get("birthDate2");
        String retirementTime1 = (String)params.get("retirementTime1");
        String retirementTime2 = (String)params.get("retirementTime2");
        String workTime1 = (String)params.get("workTime1");
        String workTime2 = (String)params.get("workTime2");

        IPage<AllEntity> page = this.page(
                new Query<AllEntity>().getPage(params),
                new QueryWrapper<AllEntity>().
                        like(StringUtils.isNotBlank(myStatus),"my_status", myStatus).
                        like(StringUtils.isNotBlank(name),"name", name).
                        eq(StringUtils.isNotBlank(idNo),"id_no",idNo).
                        eq(StringUtils.isNotBlank(personType),"person_type",personType).
                        like(StringUtils.isNotBlank(originalTroops),"original_troops", originalTroops).
                        like(StringUtils.isNotBlank(retirementStatus),"retirement_status", retirementStatus).
                        like(StringUtils.isNotBlank(duties),"duties",duties).
                        like(StringUtils.isNotBlank(county),"county", county).
                        like(StringUtils.isNotBlank(street),"street", street).
                        ge(StringUtils.isNotBlank(birthDate1),"birth_date", birthDate1).
                        le(StringUtils.isNotBlank(birthDate2),"birth_date", birthDate2).
                        ge(StringUtils.isNotBlank(retirementTime1),"retirement_time", retirementTime1).
                        le(StringUtils.isNotBlank(retirementTime2),"retirement_time", retirementTime2).
                        ge(StringUtils.isNotBlank(workTime1),"work_time", workTime1).
                        le(StringUtils.isNotBlank(workTime2),"work_time", workTime2).
                        orderByDesc("person_type")
        );

        return new PageUtils(page);
    }

    @Override
    public List<AllEntity> getTypeNum(String type, String area,String personType) {
        AllEntity allEntity = new AllEntity();
        allEntity.setCounty(area);
        allEntity.setPersonType(personType);
        if(type.equals("BRZT"))
        {
            return baseMapper.getTypeNum(allEntity);
        }else if(type.equals("ZZMM")){
            return baseMapper.getZzmmNum(allEntity);
        }else if(type.equals("NATION")){
            return baseMapper.getNationNum(allEntity);
        }else if(type.equals("SEX_GROUP")){
            return baseMapper.getSexNum(allEntity);
        }else if(type.equals("TXQSF")){
            return baseMapper.getTxqsfNum(allEntity);
        }else if(type.equals("TXSZW")){
            return baseMapper.getTxqzwNum(allEntity);
        }else if(type.equals("EMPLOYEE")){
            return baseMapper.getEmployeeNum(allEntity);
        }else if(type.equals("YJSJD")){
            return baseMapper.getYjsjdNum(allEntity);
        }else if(type.equals("YBD")){
            return baseMapper.getYbdNum(allEntity);
        }else if(type.equals("STREET")){
            return baseMapper.getStreetNum(allEntity);
        }else if(type.equals("AREA")){
            return baseMapper.getAreaNum(allEntity);
        }
        return null;
    }

    @Override
    public List<AllEntity> getStreetByContry(String contrys,String personType) {
        AllEntity allEntity = new AllEntity();
        allEntity.setCounty(contrys);
        allEntity.setPersonType(personType);
        return baseMapper.getStreetByContry(allEntity);
    }

}
